package com.fjec.common.jackson;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fjec.common.util.DateUtil;

import java.io.IOException;
import java.util.Date;

public class DateSerializer extends JsonSerializer<Date> {

    private final static String shortPattern = "yyyy-MM-dd";

    @Override
    public void serialize(Date value, JsonGenerator jgen,
                          SerializerProvider provider) throws IOException {
        String outValue = DateUtil.format(value, shortPattern);
        jgen.writeString(outValue);
    }

}
